package com.itheima.web;

import com.itheima.pojo.Result;
import com.itheima.pojo.User;
import com.itheima.service.UserService;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updateUserServlet")
public class UpdateUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            User user = BaseController.jsonStrToJavaObject(request, User.class);
            UserService userService = new UserService();
            userService.updateUser(user);
            Result result = new Result(true, "成功", null);
            BaseController.responseJson(response,result);
        } catch (Exception e) {
            e.printStackTrace();
            Result result = new Result(false, "失败", null);
            BaseController.responseJson(response,result);
        }
    }
}
